# -*- coding: utf-8 -*-
from django.conf import settings
from django.conf.urls.defaults import *
from stream.views import tag_separator

import re
import os.path

from stream import models

from django.contrib import admin
admin.autodiscover()

tag_pattern = '(\S+)'
owner_id_group = r'(?P<owner_id>(\d+))'
subscription_id_group = r'(?P<subscription_id>(\d+))'
filter_id_group = r'(?P<filter_id>(\d+))'
tag_path_re = r'(?P<tag_path>(%s%s)*%s)' % (tag_pattern, re.escape(tag_separator), tag_pattern)

urlpatterns = patterns('',
    (r'^$', 'stream.views.default'),
    (r'^add$', 'stream.views.add'),
    (r'^addForm', 'stream.views.addForm'),
    (r'^logout$', 'stream.views.logout'),
    (r'^subscribe$', 'stream.views.subscribeToUser'),

    (r'^edit$', 'stream.views.editMessage'),
    (r'^subscriptionEdit(/%s)?$' % subscription_id_group, 'stream.views.subscriptionEdit'),
    (r'^filterEdit(/%s)?$' % filter_id_group, 'stream.views.filterEdit'),
    (r'^filterDelete/%s?$' % filter_id_group, 'stream.views.filterDelete'),

    (r'^deleteMessage$', 'stream.generic_views.delete', {'model' : models.Message }),
    (r'^deleteSubscription$', 'stream.views.deleteSubscription'),

    (r'^getEntries', 'stream.views.entries'),
    (r'^getTags', 'stream.views.tags'),
    (r'^getSubscriptions', 'stream.views.subscriptions'),

    (r'displaySettings', 'stream.views.displaySettings'),

    (r'^searchUsersData', 'stream.views.searchUsersData'),
    (r'^searchUsers', 'stream.views.searchUsersView'),

    (r'^img/(?P<path>.*)$', 'django.views.static.serve', {'document_root': os.path.join(settings.MEDIA_ROOT,'img')}),
    (r'^css/(?P<path>.*)$', 'django.views.static.serve', {'document_root': os.path.join(settings.MEDIA_ROOT,'css')}),
    (r'^js/(?P<path>.*)$', 'django.views.static.serve', {'document_root': os.path.join(settings.MEDIA_ROOT,'js')}),

    (r'^openid/', include('django_openid_auth.urls')),

    (r'^%s/processTags' % owner_id_group, 'stream.views.processTags'),
    (r'^%s' % owner_id_group, 'stream.views.stream'), # This may conflict with others if change order

    #(r'^admin/doc/', include('django.contrib.admindocs.urls')),
    (r'^admin/', include(admin.site.urls)),
)
